<html>
<head>
<script type="text/javascript" src="js/chosen.jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="media/css/chosen.min.css">
	<script type="text/javascript">
		var aJaxURL			= "server-side/operations/guarantee.action.php";		//server side folder url
		var tName			= "example";													//table name
		var fName			= "add-edit-form";												//form name

		$(document).ready(function () {
			LoadTable(tName);
			GetButtons("add_button");
		});
		function LoadTable(table){
                GetDataTable(tName, aJaxURL, "get_list", 5, "", 0, "", 0, "desc");
                SetEvents("add_button", "", "", tName, fName, aJaxURL);
		}
/////-------------------------------------------------------დიალოგი-------------------------------------
		function LoadDialog(form){
				GetDialog(form,  "auto", "auto");
				$('select#latter').chosen({ search_contains: true });
				$('select#wd_id').chosen({ search_contains: true });
				
				
				GetDataTable('inner_list', aJaxURL+"?barcode="+$("#barcode").val(), "get_list1", 5, "", 0, "", 0, "desc");
/////--------------------------------------------------საგარანტიოს გაუქმება-------------------------------
				$("#disable").button().click(function() {
				    param=gsUnity.get_params("add-edit-form");
				    param.act='disable';
				    $.ajax({
				        url: aJaxURL,
				        data: param,
				        success: function(data) {
				        	  if(typeof(data.error) != "undefined")	 {
				        		    if(data.error != ""){
				        		        alert(data.error);
				        		    }else{
				        		        LoadTable(fName);
				        		        CloseDialog("add-edit-form");
							}
						}
				    }
			    });
				});
////-------------------------------------------------------ბეჭდვა------------------------------------------
				$("#print").button().click(function() {
        	    	link = "server-side/print/print_guarantee.php?wd_id="+$("#this_id").val();
        	    	var newWin = window.open(link, "JSSite", "width=600,height=800,resizable=yes,scrollbars=yes,status=yes");
        	    	newWin.focus();
        	    	newWin.onload = function() {
        	    		newWin.print();
        		    }
				      });

				$("#latter").on('change', function() {
					$("#wd_id").load(aJaxURL+"?letter="+$(this).val()+"&act=barcode",function(){ $('#wd_id').trigger("chosen:updated");});
					
					});



	    // Add - Save
	    $(document).on("click", "#save-dialog", function () {
	    	param=gsUnity.get_params("add-edit-form");
		    $.ajax({
		        url: aJaxURL,
			    data: param,
		        success: function(data) {
					if(typeof(data.error) != "undefined")
					{
						if(data.error != "")
						{
							alert(data.error);
						}else{
							LoadTable(fName);
							CloseDialog("add-edit-form");
							//$("#save-dialog").button("disable");
						}
					}
			    }
		    });
		});
		}
    </script>
<style type="text/css">
    .idls{ margin: 3px 4px;}
.ui-dialog {
  position: fixed;
}
</style>
</head>

<body>
    <div id="dt_example" class="ex_highlight_row">
        <div id="container">
            <div id="dynamic">
            	<h2 align="center">საგარანტიოები</h2>
            	   <div id="button_area">
	        			<button id="add_button">დამატება</button>
		          </div>
                <table class="display" id="example">
                    <thead>
                        <tr id="datatable_header">
                            <th>ID</th>
                            <th class="min">შტრიხკოდი</th>
                            <th style="width: 80px;">ბარათის ნომერი</th>
                            <th style="width: 100%;">აღმწერი</th>
                            <th style="width: 200px;">სტატუსი</th>

                        </tr>
                    </thead>
                    <thead>
                        <tr class="search_header">
                            <th class="colum_hidden">
                            	<input type="text" name="search_id" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_date" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_start_loc" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_end_loc" value="ფილტრი" class="search_init" />
                            </th>
                            <th>
                                <input type="text" name="search_status" value="ფილტრი" class="search_init" />
                            </th>
                        </tr>
                    </thead>
                </table>
            </div>
            <div class="spacer">
            </div>
        </div>
    </div>

    <!-- jQuery Dialog -->
    <div id="add-edit-form" class="form-dialog" title="საგარანტიო">
    	<!-- aJax -->
	</div>
</body>
</html>